using System;
using Server;
using Server.Engines.Craft;
using System;
using Server.Network;
using Server.Targeting;
using Server.Items;
using Server.Targets;
using Server;
using Server.Engines.Harvest;
using Server.Mobiles;
using Server.Engines.Quests;
using Server.Engines.Quests.Hag;
using Server.Mobiles;
using Server.Gumps;

namespace Server.Items
{
    [FlipableAttribute(0x13E3, 0x13E4)]
    public class ProspectHammer : Item
    {
        private static int MythicChanceMin;
        private static int LegendaryChanceMin;
        private static int AncientChanceMin;
        private static int MythicChanceMax;
        private static int LegendaryChanceMax;
        private static int AncientChanceMax;
        private static int ao;
        //private static Item rawmat;

        [Constructable]
        public ProspectHammer()
            : base(0x13E3)
        {
            Name = "Prospect Hammer";
            Weight = 8.0;
            Layer = Layer.OneHanded;
            Hue = 188;
        }



        public override void OnDoubleClick(Mobile from)
        {
            if (IsChildOf(from.Backpack) || Parent == from)
            {
                if (from.Skills[SkillName.Mining].Base >= 100 && from.Skills[SkillName.Blacksmith].Base >= 100 && from.Skills[SkillName.ItemID].Base >= 100)
                {
                    from.Target = new prospect(this);
                    from.SendMessage("What do you want to use this item on?");
                }
                else
                {
                    from.SendMessage("You dont know what to do whit that tool!");
                }
            }
            else
            {
                from.SendMessage("The tool have to be in your backpack or hand!");
            }
        }
        public class prospect : Target
        {

            private Item m_Item;

            public prospect(Item item)
                : base(1, false, TargetFlags.None)
            {
                m_Item = item;
            }
            protected override void OnTargetOutOfRange(Mobile from, object targeted)
            {
                if (targeted is UnholyBone && from.InRange(((UnholyBone)targeted), 12))
                    ((UnholyBone)targeted).Carve(from, m_Item);
                else
                    base.OnTargetOutOfRange(from, targeted);
            }

            protected override void OnTarget(Mobile from, object targeted)
            {
                if (targeted is AgapiteOre || targeted is VeriteOre || targeted is ValoriteOre)
                {

                    if (targeted is AgapiteOre)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(AgapiteOre));
                        ProspectHammer.MythicChanceMax = 5;
                        ProspectHammer.LegendaryChanceMax = 35;
                        ProspectHammer.AncientChanceMax = 100;

                        ProspectHammer.MythicChanceMin = 0;
                        ProspectHammer.LegendaryChanceMin = 5;
                        ProspectHammer.AncientChanceMin = 35;
                    }
                    else if (targeted is VeriteOre)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(VeriteOre));
                        ProspectHammer.MythicChanceMax = 10;
                        ProspectHammer.LegendaryChanceMax = 60;
                        ProspectHammer.AncientChanceMax = 100;

                        ProspectHammer.MythicChanceMin = 0;
                        ProspectHammer.LegendaryChanceMin = 10;
                        ProspectHammer.AncientChanceMin = 60;

                    }
                    else if (targeted is ValoriteOre)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(ValoriteOre));
                        ProspectHammer.MythicChanceMax = 20;
                        ProspectHammer.LegendaryChanceMax = 80;
                        ProspectHammer.AncientChanceMax = 100;

                        ProspectHammer.MythicChanceMin = 0;
                        ProspectHammer.LegendaryChanceMin = 20;
                        ProspectHammer.AncientChanceMin = 80;

                    }

                    if (ProspectHammer.ao >= 5)
                    {
                        from.SendMessage("You have prospected a ore.");
                        if (targeted is AgapiteOre)
                        {
                            from.Backpack.ConsumeTotal(typeof(AgapiteOre), 5);
                        }

                        else if (targeted is VeriteOre)
                        {
                            from.Backpack.ConsumeTotal(typeof(VeriteOre), 5);
                        }
                        else if (targeted is ValoriteOre)
                        {
                            from.Backpack.ConsumeTotal(typeof(ValoriteOre), 5);
                        }

                        int cgem = (Utility.Random(6));


                        switch (cgem)
                        {
                            case 0://RUBY-------------------------------------------------
                                {
                                    int cc = (Utility.Random(100));
                                    if (cc < ProspectHammer.MythicChanceMax && cc > ProspectHammer.MythicChanceMin)
                                    {
                                        from.AddToBackpack(new RawMythicRuby());
                                    }
                                    else if (cc < ProspectHammer.LegendaryChanceMax && cc > ProspectHammer.LegendaryChanceMin)
                                    {
                                        from.AddToBackpack(new RawLegendaryRuby());
                                    }
                                    else if (cc < ProspectHammer.AncientChanceMax && cc > ProspectHammer.AncientChanceMin)
                                    {
                                        from.AddToBackpack(new RawAncientRuby());
                                    }
                                    else
                                    {
                                        from.SendMessage("You didnt get anything!!!!");
                                    }
                                    break;
                                }
                            case 1://TOURMALINE--------------------------------------------
                                {
                                    int cc = (Utility.Random(100));
                                    if (cc < ProspectHammer.MythicChanceMax && cc > ProspectHammer.MythicChanceMin)
                                    {
                                        from.AddToBackpack(new RawMythicTourmaline());
                                    }
                                    else if (cc < ProspectHammer.LegendaryChanceMax && cc > ProspectHammer.LegendaryChanceMin)
                                    {
                                        from.AddToBackpack(new RawLegendaryTourmaline());
                                    }
                                    else if (cc < ProspectHammer.AncientChanceMax && cc > ProspectHammer.AncientChanceMin)
                                    {
                                        from.AddToBackpack(new RawAncientTourmaline());
                                    }
                                    else
                                    {
                                        from.SendMessage("You didnt get anything!!!!");
                                    }
                                    break;
                                }
                            case 2://AMETHYST----------------------------------------------
                                {
                                    int cc = (Utility.Random(100));
                                    if (cc < ProspectHammer.MythicChanceMax && cc > ProspectHammer.MythicChanceMin)
                                    {
                                        from.AddToBackpack(new RawMythicAmethyst());
                                    }
                                    else if (cc < ProspectHammer.LegendaryChanceMax && cc > ProspectHammer.LegendaryChanceMin)
                                    {
                                        from.AddToBackpack(new RawLegendaryAmethyst());
                                    }
                                    else if (cc < ProspectHammer.AncientChanceMax && cc > ProspectHammer.AncientChanceMin)
                                    {
                                        from.AddToBackpack(new RawAncientAmethyst());
                                    }
                                    else
                                    {
                                        from.SendMessage("You didnt get anything!!!!");
                                    }
                                    break;
                                }
                            case 3://SKULL--------------------------------------------------
                                {
                                    int cc = (Utility.Random(100));
                                    if (cc < ProspectHammer.MythicChanceMax && cc > ProspectHammer.MythicChanceMin)
                                    {
                                        from.AddToBackpack(new RawMythicSkull());
                                    }
                                    else if (cc < ProspectHammer.LegendaryChanceMax && cc > ProspectHammer.LegendaryChanceMin)
                                    {
                                        from.AddToBackpack(new RawLegendarySkull());
                                    }
                                    else if (cc < ProspectHammer.AncientChanceMax && cc > ProspectHammer.AncientChanceMin)
                                    {
                                        from.AddToBackpack(new RawAncientSkull());
                                    }
                                    else
                                    {
                                        from.SendMessage("You didnt get anything!!!!");
                                    }
                                    break;
                                }
                            case 4://SAPPHIRE-------------------------------------------------
                                {
                                    int cc = (Utility.Random(100));
                                    if (cc < ProspectHammer.MythicChanceMax && cc > ProspectHammer.MythicChanceMin)
                                    {
                                        from.AddToBackpack(new RawMythicSapphire());
                                    }
                                    else if (cc < ProspectHammer.LegendaryChanceMax && cc > ProspectHammer.LegendaryChanceMin)
                                    {
                                        from.AddToBackpack(new RawLegendarySapphire());
                                    }
                                    else if (cc < ProspectHammer.AncientChanceMax && cc > ProspectHammer.AncientChanceMin)
                                    {
                                        from.AddToBackpack(new RawAncientSapphire());
                                    }
                                    else
                                    {
                                        from.SendMessage("You didnt get anything!!!!");
                                    }
                                    break;
                                }
                            case 5://DIAMOND----------------------------------------------------
                                {
                                    int cc = (Utility.Random(100));
                                    if (cc < ProspectHammer.MythicChanceMax && cc > ProspectHammer.MythicChanceMin)
                                    {
                                        from.AddToBackpack(new RawMythicDiamond());
                                    }
                                    else if (cc < ProspectHammer.LegendaryChanceMax && cc > ProspectHammer.LegendaryChanceMin)
                                    {
                                        from.AddToBackpack(new RawLegendaryDiamond());
                                    }
                                    else if (cc < ProspectHammer.AncientChanceMax && cc > ProspectHammer.AncientChanceMin)
                                    {
                                        from.AddToBackpack(new RawAncientDiamond());
                                    }
                                    else
                                    {
                                        from.SendMessage("You didnt get anything!!!!");
                                    }
                                    break;
                                }
                            case 6://EMERALD-----------------------------------------------------
                                {
                                    int cc = (Utility.Random(100));
                                    if (cc < ProspectHammer.MythicChanceMax && cc > ProspectHammer.MythicChanceMin)
                                    {
                                        from.AddToBackpack(new RawMythicEmerald());
                                    }
                                    else if (cc < ProspectHammer.LegendaryChanceMax && cc > ProspectHammer.LegendaryChanceMin)
                                    {
                                        from.AddToBackpack(new RawLegendaryEmerald());
                                    }
                                    else if (cc < ProspectHammer.AncientChanceMax && cc > ProspectHammer.AncientChanceMin)
                                    {
                                        from.AddToBackpack(new RawAncientEmerald());
                                    }
                                    else
                                    {
                                        from.SendMessage("You didnt get anything!!!!");
                                    }
                                    break;
                                }

                        }

                    }
                    else
                    {
                        from.SendMessage("You need at least 5 ores in your backpack!");
                    }
                    return;
                }
                else if (targeted is HeartwoodLog || targeted is BloodwoodLog || targeted is FrostwoodLog)
                {

                    if (targeted is HeartwoodLog)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(HeartwoodLog));
                        ProspectHammer.MythicChanceMax = 5;
                        ProspectHammer.LegendaryChanceMax = 35;
                        ProspectHammer.AncientChanceMax = 100;

                        ProspectHammer.MythicChanceMin = 0;
                        ProspectHammer.LegendaryChanceMin = 5;
                        ProspectHammer.AncientChanceMin = 35;
                    }
                    else if (targeted is BloodwoodLog)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(BloodwoodLog));
                        ProspectHammer.MythicChanceMax = 10;
                        ProspectHammer.LegendaryChanceMax = 60;
                        ProspectHammer.AncientChanceMax = 100;

                        ProspectHammer.MythicChanceMin = 0;
                        ProspectHammer.LegendaryChanceMin = 10;
                        ProspectHammer.AncientChanceMin = 60;

                    }
                    else if (targeted is FrostwoodLog)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(FrostwoodLog));
                        ProspectHammer.MythicChanceMax = 20;
                        ProspectHammer.LegendaryChanceMax = 80;
                        ProspectHammer.AncientChanceMax = 100;

                        ProspectHammer.MythicChanceMin = 0;
                        ProspectHammer.LegendaryChanceMin = 20;
                        ProspectHammer.AncientChanceMin = 80;

                    }

                    if (ProspectHammer.ao >= 5)
                    {
                        from.SendMessage("You have prospected a log.");
                        if (targeted is HeartwoodLog)
                        {
                            from.Backpack.ConsumeTotal(typeof(HeartwoodLog), 5);
                        }

                        else if (targeted is BloodwoodLog)
                        {
                            from.Backpack.ConsumeTotal(typeof(BloodwoodLog), 5);
                        }
                        else if (targeted is FrostwoodLog)
                        {
                            from.Backpack.ConsumeTotal(typeof(FrostwoodLog), 5);
                        }


                        int cc = (Utility.Random(100));
                        if (cc < ProspectHammer.MythicChanceMax && cc > ProspectHammer.MythicChanceMin)
                        {
                            from.AddToBackpack(new RawMythicCrust());
                        }
                        else if (cc < ProspectHammer.LegendaryChanceMax && cc > ProspectHammer.LegendaryChanceMin)
                        {
                            from.AddToBackpack(new RawLegendaryCrust());
                        }
                        else if (cc < ProspectHammer.AncientChanceMax && cc > ProspectHammer.AncientChanceMin)
                        {
                            from.AddToBackpack(new RawAncientCrust());
                        }
                        else
                        {
                            from.SendMessage("You didnt get anything!!!!");
                        }



                    }
                    else
                    {
                        from.SendMessage("You need at least 5 logs in your backpack!");
                    }
                    //---------------------------------------------------------------------------------------------------------------------------------------------
                }
                else if (targeted is RawMythicRuby || targeted is RawMythicTourmaline || targeted is RawMythicAmethyst || targeted is RawMythicSkull || targeted is RawMythicSapphire || targeted is RawMythicDiamond || targeted is RawMythicEmerald)
                {

                    if (targeted is RawMythicRuby)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(RawMythicRuby));
                        if (ProspectHammer.ao > 0)
                        {
                            from.Backpack.ConsumeTotal(typeof(RawMythicRuby), 1);
                            ranmat(from);
                        }
                    }
                    else if (targeted is RawMythicTourmaline)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(RawMythicTourmaline));
                        if (ProspectHammer.ao > 0)
                        {
                            from.Backpack.ConsumeTotal(typeof(RawMythicTourmaline), 1);
                            ranmat(from);
                        }
                    }
                    else if (targeted is RawMythicAmethyst)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(RawMythicAmethyst));
                        if (ProspectHammer.ao > 0)
                        {
                            from.Backpack.ConsumeTotal(typeof(RawMythicAmethyst), 1);
                            ranmat(from);
                        }
                    }
                    else if (targeted is RawMythicSkull)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(RawMythicSkull));
                        if (ProspectHammer.ao > 0)
                        {
                            from.Backpack.ConsumeTotal(typeof(RawMythicSkull), 1);
                            ranmat(from);
                        }
                    }
                    else if (targeted is RawMythicSapphire)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(RawMythicSapphire));
                        if (ProspectHammer.ao > 0)
                        {
                            from.Backpack.ConsumeTotal(typeof(RawMythicSapphire), 1);
                            ranmat(from);
                        }
                    }
                    else if (targeted is RawMythicDiamond)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(RawMythicDiamond));
                        if (ProspectHammer.ao > 0)
                        {
                            from.Backpack.ConsumeTotal(typeof(RawMythicDiamond), 1);
                            ranmat(from);
                        }
                    }
                    else if (targeted is RawMythicEmerald)
                    {
                        ProspectHammer.ao = from.Backpack.GetAmount(typeof(RawMythicEmerald));
                        if (ProspectHammer.ao > 0)
                        {
                            from.Backpack.ConsumeTotal(typeof(RawMythicEmerald), 1);
                            ranmat(from);
                        }


                    }
                    else
                    {
                        from.SendMessage("You need at least 1 Raw Mythic Material in your backpack!");
                    }
                    //-----------------------------------------------------------------------------------------------------------------------

                }
                else
                {
                    from.SendMessage("You cant use it that way!");
                    return;
                }

            }
        }
        public static void ranmat(Mobile o)
        {
            int gen = (Utility.Random(2));


            switch (gen)
            {
                case 0:
                    {
                        o.AddToBackpack(new RawCrystal());
                        break;
                    }
                case 1:
                    {
                        o.AddToBackpack(new RawRune());
                        break;
                    }
                case 2:
                    {
                        o.AddToBackpack(new RawGlimmeringPiece());
                        break;
                    }


            }
        }

        public ProspectHammer(Serial serial)
            : base(serial)
        {
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            writer.Write((int)0); // version
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();
        }
    }
}